package com.navigationtest;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;

import com.hjq.bar.OnTitleBarListener;
import com.myatest.BR;
import com.myatest.R;
import com.pbase.tools.Logger;
import com.pbase.ui.page.DataBindingConfig;

import androidx.navigation.NavController;
import androidx.navigation.Navigation;

/**
 * User: psn
 * Date: 2021/12/11
 */
public class Test5Fragment extends NavigationViewFragment {
    private Test5ViewModel mViewModel;
    @Override
    protected void onCreateViewBefore() {

    }

    @Override
    protected void onCreateViewAfter() {
        super.onCreateViewAfter();
    }

    @Override
    protected void initViewModel() {
        mViewModel =getFragmentScopeViewModel(Test5ViewModel.class);
    }

    @Override
    protected DataBindingConfig getDataBindingConfig() {
        return new DataBindingConfig(R.layout.frg_text5, BR.vm,mViewModel)
                .addBindingParam(BR.click, new Test5Fragment.Onclick())
         .addBindingParam(BR.onkey, new Test5Fragment.Onkey()) ;
    }

    public class Onclick {
        public void btn_a(View v) {
            Logger.e(getClass(),"btn_a");
            mViewModel.age.setValue(1111);
            Bundle bundle = new Test5FragmentArgs.Builder().setAge(1111).build().toBundle();
            NavController controller = Navigation.findNavController( v);//找到button归属的controller
            controller.navigate(R.id.action_test5Fragment_to_startFragment,bundle);
//            controller.getCurrentBackStackEntry().getSavedStateHandle().get()
        }

    }
    public class TitleBarListener implements OnTitleBarListener {

        @Override
        public void onLeftClick(View view) {
            left();
        }

        @Override
        public void onTitleClick(View view) {

        }

        @Override
        public void onRightClick(View view) {

        }
    }
    @Override
    public void left() {
        getActivity().finish();
    }
    public class Onkey implements View.OnKeyListener {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            Logger.e(getClass(),"Test5Fragment NavigationViewFragment handleOnBackPressed");
            if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
            }
            return false;
        }
    }

}
